﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using COM.Rights.BLL;
using COM.Rights.Model;
using System.Data;
using System.Data.SqlClient;
using COM.PreAlarm.BLL;
using COM.PreAlarm.Model;

namespace UDPWinListen
{
    public  class Common
    {
        public string[] GetIPAndPort()
        {
            string[] str = new string[3];
            int i = 0;
            string line;
            try
            {
                using (StreamReader sr = new StreamReader(@"IpAndPort.txt"))
                {
                    line = sr.ReadLine();
                    while (line != null)
                    {
                        str[i] = line;
                        i++;
                        line = sr.ReadLine();
                    }
                }
            }
            catch (Exception e)
            {

                throw new Exception("获取ip和端口"+ e.Message) ;
            }
            return str;
           
        }

        //从新设置ip和端口号码
        public void WriteIPAndPort(string ip,string port,string sendPort)
        {
            using (StreamWriter sw = new StreamWriter(@"IpAndPort.txt"))
            {
                sw.WriteLine(ip);
                sw.WriteLine(port);
                sw.WriteLine(sendPort);
            }
 
        }

        //将当前年月日转化位字符串“2012-03-01”
        public string GetDateString()
        {
            DateTime dt = DateTime.Now;
            int dty = dt.Year;
            int dtm = dt.Month;
            int dtd = dt.Day;
            string ymd = dty + "-" + GetMonthOrDay(dtm) + "-" + GetMonthOrDay(dtd);
            return ymd;
        }

        //处理日期月份或日小于10的数据 小于10的前面加0
        private string GetMonthOrDay(int x)
        {
            string dtmd;
            if (x < 10)
            {
                dtmd = "0" + x;
            }
            else
            {
                dtmd = x.ToString();
            }
            return dtmd;
        }

        public static DataTable GetSetMsgData()
        {
            DataTable dt = new DataTable();
            try
            {
                Equip_SetMsg _Equip_MsgSent = new Equip_SetMsg();
                List<DBParameter> _listDBParameter = new List<DBParameter>();
                _listDBParameter.Add(new DBParameter("@TranType", "SetMsgList"));

                IDataReader sdr = _Equip_MsgSent.ExecuteReader("[dbo].[Msg_Sel]", _listDBParameter, System.Data.CommandType.StoredProcedure);
                dt.Load(sdr);

            }
            catch (Exception ex)
            {//发生异常（防止网络连接造成的异常，不做处理）

            }
            return dt;
 
        }


    }
}
